<?php
/**
 * Página principal
 * @package default
 * @author Thiago Segato Antunes
 * @version 1.0
 * @copyright atitudeweb
 * @license http://opensource.org/licenses/gpl-3.0.html GPL General Public License
*/
define ( 'EXEC', 1 );
define ( 'ATITUDE_BASE', dirname ( __FILE__ ) );
define ( 'DS', DIRECTORY_SEPARATOR );
require_once (ATITUDE_BASE . DS . 'includes' . DS . 'framework.php');

// Verificando o logout do sistema
if (@$_GET ['logout']) {
	$auth->logout ();
	$user = null;
}

ob_start ();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<title><?php echo Config::SYSTEM; ?></title>
	
	<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="assets/css/bootstrap-theme.css">
	<link rel="stylesheet" href="assets/css/bootstrap-select.min.css" type="text/css" />
	<link rel="stylesheet" href="assets/css/font-awesome.min.css">	
	<link rel="stylesheet" href="assets/css/estilo.css">
	<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css">	
	<link rel="shortcut icon" href="assets/assets/favicon.ico" type="image/x-icon" />
	
	<script type="text/javascript" src="assets/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="assets/js/jquery.datatables.min.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap-select.min.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap3-typeahead.min.js"></script>
	<script type="text/javascript" src="assets/js/scripts.js"></script>
	<script type="text/javascript" src="assets/js/framework.js"></script>
	<script type="text/javascript" src="assets/js/moment.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap-datetimepicker.min.js"></script>	
	<script type="text/javascript" src="assets/js/pt-br.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap-filestyle.js"></script>	
	<atitudeweb:include type="head" />
</head>
<body>
	<div id="corpo">
		<?php
		if (! $user) {
			include ('includes/login.php');
		} else {
			include ('includes/header.php');
			echo '<div id="conteudo" class="container">';
			if (! @$_GET ['page']) {
				include ('includes/home.php');
			} else {
				if (file_exists ( 'modules/' . $_GET ['page'] . '.php' )) {
					include ('modules/' . $_GET ['page'] . '.php');
				} else {
					echo 'Módulo não encontrado: <b>' . 'modules/' . $_GET ['page'] . '.php</b>';
				}
			}
			echo '</div>';
			include ('includes/footer.php');
		}
		?>		
	</div>
</body>
</html>
<?php
$data = ob_get_contents ();
ob_end_clean ();
$matches = array ();
if (preg_match_all ( '#<atitudeweb:include\ type="([^"]+)" (.*)\/>#iU', $data, $matches )) {
	if ($matches [1] [0] == 'head') {
		$buffer = '';
		for($i = 0; $i < count ( Controller::$head ); $i ++) {
			$buffer .= Controller::$head [$i] . "\n";
		}
		$data = str_replace ( $matches [0] [0], $buffer, $data );
	}
}
echo $data;
if (@$_POST ['info']) {
	Util::notice ( $_POST ['title'], $_POST ['text'], $_POST ['type'], $_POST ['icon'], $_POST ['timer'] );
}
?>